//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.tencent.bugly.crashreport.crash;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import com.tencent.bugly.crashreport.common.info.b;
import com.tencent.bugly.crashreport.common.strategy.a;
import com.tencent.bugly.proguard.u;
import com.tencent.bugly.proguard.x;
import com.tencent.bugly.proguard.z;

public class BuglyBroadcastReceiver extends BroadcastReceiver {
    private IntentFilter a = new IntentFilter();
    private Context b;
    private String c;
    private static BuglyBroadcastReceiver d = null;
    private boolean e = true;

    public static synchronized BuglyBroadcastReceiver getInstance() {
        if (d == null) {
            d = new BuglyBroadcastReceiver();
        }

        return d;
    }

    public BuglyBroadcastReceiver() {
    }

    public synchronized void addFilter(String var1) {
        if (!this.a.hasAction(var1)) {
            this.a.addAction(var1);
        }

        x.c("add action %s", new Object[]{var1});
    }

    public synchronized void register(Context var1) {
        this.b = var1;
        z.a(new Runnable() {
            public final void run() {
                try {
                    x.a(BuglyBroadcastReceiver.d.getClass(), "Register broadcast receiver of Bugly.", new Object[0]);
                    synchronized(BuglyBroadcastReceiver.this) {
                        BuglyBroadcastReceiver.this.b.registerReceiver(BuglyBroadcastReceiver.d, BuglyBroadcastReceiver.this.a);
                    }
                } catch (Throwable var4) {
                    var4.printStackTrace();
                }

            }
        });
    }

    public synchronized void unregister(Context var1) {
        try {
            x.a(this.getClass(), "Unregister broadcast receiver of Bugly.", new Object[0]);
            var1.unregisterReceiver(this);
            this.b = var1;
        } catch (Throwable var2) {
            if (!x.a(var2)) {
                var2.printStackTrace();
            }

        }
    }

    public final void onReceive(Context var1, Intent var2) {
        try {
            this.a(var1, var2);
        } catch (Throwable var3) {
            if (!x.a(var3)) {
                var3.printStackTrace();
            }

        }
    }

    private synchronized boolean a(Context var1, Intent var2) {
        if (var1 != null && var2 != null && var2.getAction().equals("android.net.conn.CONNECTIVITY_CHANGE")) {
            if (this.e) {
                this.e = false;
                return true;
            } else {
                String var10 = com.tencent.bugly.crashreport.common.info.b.c(this.b);
                x.c("is Connect BC " + var10);
                x.a("network %s changed to %s", this.c, var10);
                if (var10 == null) {
                    this.c = null;
                    return true;
                } else {
                    String var3 = this.c;
                    this.c = var10;
                    long var5 = System.currentTimeMillis();
                    a var4 = com.tencent.bugly.crashreport.common.strategy.a.a();
                    u var7 = u.a();
                    com.tencent.bugly.crashreport.common.info.a var8 = com.tencent.bugly.crashreport.common.info.a.a(var1);
                    if (var4 != null && var7 != null && var8 != null) {
                        if (!var10.equals(var3)) {
                            if (var5 - var7.a(com.tencent.bugly.crashreport.crash.c.a) > 30000L) {
                                x.a("try to upload crash on network changed.");
                                c var9;
                                if ((var9 = com.tencent.bugly.crashreport.crash.c.a()) != null) {
                                    var9.a(0L);
                                }
                            }

                            if (var5 - var7.a(1001) > 30000L) {
                                x.a("try to upload userinfo on network changed.");
                                com.tencent.bugly.crashreport.biz.b.a.b();
                            }
                        }

                        return true;
                    } else {
                        x.d("not inited BC not work", new Object[0]);
                        return true;
                    }
                }
            }
        } else {
            return false;
        }
    }
}
